<template>
	<view class="view">
		<view
			style="width: 100%;height: 30%; margin-left: 10%;display: flex;justify-content: left; align-items: center;">
			<view @click="login" v-if="logindex!=1" style="display: flex;flex-direction: column;align-items: center;">
				<image src="../../static/icon/login.png" mode="aspectFit" style="width: 45px;height: 45px;"></image>
				<text>未登录</text>
			</view>
			<view v-else style="display: flex;flex-direction: column;align-items: center;">
				<image :src="user.userImage" mode="aspectFit" style="width: 45px;height: 45px;"></image>
				<text>{{user.userName}}</text>
			</view>
		</view>
		<view class="" style="width: 100%; height: 5px; background-color: #D3D3D3;"></view>
		<view style="margin-top: 10px; display: flex;flex-direction: column;">
			<text style="padding-top: 10px; border-bottom:1px solid #D3D3D3;width: 100%;" @click="information">个人信息</text>

			<text style="padding-top: 10px; border-bottom:1px solid #D3D3D3;width: 100%;" @click="money">我的钱包</text>
			<text style="padding-top: 10px; border-bottom:1px solid #D3D3D3;width: 100%;" @click="shopping">我的购物车</text>
			<text style="padding-top: 10px; border-bottom:1px solid #D3D3D3;width: 100%;" @click="order">我的订单</text>
		</view>
		<view class="" style="margin-top: 10%; width: 100%; height: 5px; background-color: #D3D3D3;"></view>
		<view class="" style="display: flex; margin-top: 10px;">
			<button type="warn" @click="exit">退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logindex: -1,
				user: {}
			}
		},
		methods: {
			order(){
					if (uni.getStorageSync('token')) {
						uni.navigateTo({
							url: '/pages/order/order',
							success: res => {},
							fail: () => {},
							complete: () => {}
						});
					}
			},
			shopping(){
				if (uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/shopping/shopping',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			information() {
				if (uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/Information/Information',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			money() {
				if (uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/wallet/wallet',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			exit() {
				uni.request({
					url: this.api.logout,
					method: 'POST',
					data: {},
					success: res => {
						if (res.data.code == 200) {
							uni.removeStorageSync('token')
							this.logindex = -1
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			login() {
				uni.navigateTo({
					url: '/pages/login/login',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad() {
			if (uni.getStorageSync('token')) {
				this.user = uni.getStorageSync('token')
				this.logindex = 1
			}
		}
	}
</script>

<style lang="scss">
	page,
	.view {
		width: 100%;
		height: 100%;
		// background-color:#D3D3D3 ;
	}
</style>
